home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 16.0 KB | 579 lines | [TEXT/MPS ] |
- #
- # File: Gestalt.vulib
- #
- # Contains: Sample tasks for working with standard Gestalt calls.
- # For a more detailed description of these tasks, refer to
- # Virtual User Example Libraries reference document included
- # with the Virtual User 2.1 product. This document contains
- # listings of all possible return values.
- #
- # Requirements: Gestalt support on target machine. Note that the task
- # SetGestaltGlobals() needs to be called at the beginning
- # of every script that is to use the Gestalt.vulib library
- # of tasks.
- #
- # Written by: David Gaxiola, Phil Thompson, and Chad Williams
- #
- # Copyright: © 1992-96 by Apple Computer, Inc., all rights reserved.
- #
- # Change History (most recent first):
- #
- # 3/15/96 CMW Updated for 2.1 format of Gestalt returned values.
- # 11/24/92 PRT Modified some repetitive if-return statements,
- # allowed more types for GetGestaltMachineType.
- # 8/18/92 DGG Added IsGestaltLongError task
- # 8/12/92 DGG EasyAccess GestaltTask modified
- # 8/6/92 DGG Some tasks modified to use bitwise operators.
- # Gestalt's inability to report full 8 MB of
- # physical memory.
- # 8/4/92 DGG Renamed all tasks.
- # 7/22/92 DGG Created.
- #
- # To Do:
- #
-
- (************************************************************************************
- * Task SetGestaltGlobals()
- * Will set global variables of possible Gestalt error responses.
- ************************************************************************************)
- task SetGestaltGlobals()
- begin
- global kGestaltNoErr := 0;
- global kGestaltUnknownErr := -5550;
- global kGestaltUndefSelectorErr := -5551;
- end;
-
- (************************************************************************************
- * Task GestaltGetError(gestaltAnswer)
- * Will return the error portion of a Gestalt call response.
- ************************************************************************************)
- task GestaltGetError(gestaltAnswer := {0,0})
- begin
- return gestaltAnswer[1];
- end;
-
- (************************************************************************************
- * Task GestaltGetLongError(gestaltAnswer)
- * Will return a longer error response in the form of a string.
- ************************************************************************************)
- task GestaltGetLongError(gestaltAnswer := {0,0})
- begin
- global kGestaltNoErr;
- global kGestaltUnknownErr;
- global kGestaltUndefSelectorErr;
-
- gesErr := GestaltGetError(gestaltAnswer);
-
- if gesErr = kGestaltNoErr
- return "No error";
-
- if gesErr = kGestaltUnknownErr
- return "Error: Could not obtain response";
-
- if gesErr = kGestaltUndefSelectorErr
- return "Error: Undefined selector";
-
- return "Error: Unknown error code: {gesErr}";
- end;
-
- (************************************************************************************
- * Task IsGestaltLongError(gestaltLongErr)
- * Will check a list of known Long Error responses to see if the string passed
- * is in fact an error.
- ************************************************************************************)
- task IsGestaltLongError(gestaltLongErr := "No error")
- begin
- if gestaltLongErr = /Error≈/
- return true;
- else
- return false;
- end;
-
- (************************************************************************************
- * Task GestaltGetValue(gestaltAnswer)
- * Will return the high word and low word pair of a Gestalt response in
- * the form of a list.
- ************************************************************************************)
- task GestaltGetValue(gestaltAnswer := {0,0})
- begin
- return gestaltAnswer[2];
- end;
-
- (************************************************************************************
- * Task GestaltGetHiWord(gestaltAnswer)
- * Will return the high word portion from the answer of a Gestalt response.
- ************************************************************************************)
- task GestaltGetHiWord(gestaltAnswer := {0,0})
- begin
- return( GestaltGetValue(gestaltAnswer) >> 16 );
- end;
-
- (************************************************************************************
- * Task GestaltGetLoWord(gestaltAnswer)
- * Will return the low word portion from the answer of a Gestalt response.
- ************************************************************************************)
- task GestaltGetLoWord(gestaltAnswer := {0, 0})
- begin
- return( GestaltGetValue(gestaltAnswer) & 0x0000FFFF );
- end;
-
- (************************************************************************************
- * All of the following tasks take the form GetGestaltXXX(). Their names
- * are parallel to the gestaltXXX selectors as defined in InsideMacintosh
- * Volume VI. For instance the selector defined as the variable
- * gestaltAddressingModeAttr has the equivalent VU task defined as
- * GetGestaltAddressingModeAttr.
- * These tasks will return either a string representing a response, a string
- * with the prefix "unkn" if a good response was returned but unrecognized
- * by the tasks, or an error message string. The only exceptions to this are
- * the GetGestaltLogicalRAMSize and GetGestaltPhysicalRAMSize which will
- * return integers instead of strings.
- ************************************************************************************)
-
- (************************************************************************************
- * Task GetGestaltAddressingModeAttr()
- * Will return the state of 32Bit addressing.
- ************************************************************************************)
- task GetGestaltAddressingModeAttr()
- begin
- gesAns := Gestalt('addr');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- addrReturnVal := "";
- addrAns := GestaltGetValue(gesAns);
- if addrAns & (1 << 0)
- addrReturnVal := addrReturnVal + "32BitAddressing ";
- if addrAns & (1 << 1)
- addrReturnVal := addrReturnVal + "32BitSysZone ";
- if addrAns & (1 << 2)
- addrReturnVal := addrReturnVal + "32BitCapable ";
- if not ((addrAns & (1 << 0)) or (addrAns & (1 << 1)) or (addrAns & (1 << 2)))
- addrReturnVal := addrReturnVal + "unknAddressingModeAttr";
- return addrReturnVal;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltEasyAccessAttr()
- * Will return the current attributes to the Easy Access settings. Note that
- * the values returned by the gestalt call and the interpretation of these as
- * described in Inside Macintosh Volume VI do not match. If EasyAccess is not
- * turned on in any way on the target, an "Undefined Selector" string will be
- * returned. If EasyAccess is active, the "EasyPresent" value is returned.
- ************************************************************************************)
- task GetGestaltEasyAccessAttr()
- begin
- gesAns := Gestalt('easy');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- easyReturnVal := "";
- easyAns := GestaltGetValue(gesAns);
- if easyAns & (1 << 0)
- easyReturnVal := easyReturnVal + "EasyPresent ";
- if easyAns & (1 << 1)
- easyReturnVal := easyReturnVal + "EasyOn ";
- if easyAns & (1 << 2)
- easyReturnVal := easyReturnVal + "EasySticky ";
- if easyAns & (1 << 3)
- easyReturnVal := easyReturnVal + "EasyLocked ";
- if not ((easyAns & (1 << 0)) or (easyAns & (1 << 1)) or (easyAns & (1 << 2)) or (easyAns & (1 << 3)))
- easyReturnVal := easyReturnVal + "unknEasyAccess";
- return easyReturnVal;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltFPUType()
- * Will return the type of floating point coprocessor on the target.
- ************************************************************************************)
- task GetGestaltFPUType()
- begin
- gesAns := Gestalt('fpu ');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- fpuAns := GestaltGetValue(gesAns);
-
- if fpuAns = 0
- return "NoFPU";
-
- if fpuAns = 1
- return "68881";
-
- if fpuAns = 2
- return "68882";
-
- if fpuAns = 3
- return "68040FPU";
-
- return "unknFPU";
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltKeyboardType()
- * Will return the type of keyboard in use on the target.
- ************************************************************************************)
- task GetGestaltKeyboardType()
- begin
- gesAns := Gestalt('kbd ');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- kbdAns := GestaltGetValue(gesAns);
-
- if kbdAns = 1
- return "MacKbd";
-
- if kbdAns = 2
- return "MacKbdAndPad";
-
- if kbdAns = 3
- return "MacPlusKbd";
-
- if kbdAns = 4
- return "ExtADBKbd";
-
- if kbdAns = 5
- return "StdADBKbd";
-
- if kbdAns = 6
- return "PrtblADBKbd";
-
- if kbdAns = 7
- return "PrtblISOKbd";
-
- if kbdAns = 8
- return "StdISOADBKbd";
-
- if kbdAns = 9
- return "ExtISOADBKbd";
-
- if kbdAns = 10
- return "ADBKbdII";
-
- if kdbAns = 11
- return "ADBISOKbdII";
-
- return "unknKbd";
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltLogicalRAMSize()
- * Will return the logical amount of RAM on the target. This is a combination
- * of physical RAM and virtual memory. This value is an integer of the amount
- * of memory in megabytes.
- ************************************************************************************)
- task GetGestaltLogicalRAMSize()
- begin
- gesAns := Gestalt('lram');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- theHiWord := GestaltGetHiWord(gesAns);
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltMachineType()
- * Will return the type of machine the target is.
- * NOTE: the value "Classic" does not refer to the modern Macintosh
- * Classic, but rather to the original Macintosh. The newer model is
- * referenced by the machine name "MacClassic". This phrasing was used
- * to stay consistent with the values referenced in Inside Macintosh VI
- * and MPW include files. Note also that the Macintosh Classic II model
- * is referred to as "ClassicII" by the task.
- * This list was last updated 03/15/96.
- ************************************************************************************)
- task GetGestaltMachineType()
- begin
- gesAns := Gestalt('mach');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- machAns := GestaltGetLoWord(gesAns);
-
- switch( machAns )
- begin
- case 1:
- return "Classic";
- case 2:
- return "MacXL";
- case 3:
- return "Mac512KE";
- case 4:
- return "MacPlus";
- case 5:
- return "MacSE";
- case 6:
- return "MacII";
- case 7:
- return "MacIIx";
- case 8:
- return "MacIIcx";
- case 9:
- return "MacSE030";
- case 10:
- return "Portable";
- case 11:
- return "MacIIci";
- case 13:
- return "MacIIfx";
- case 17:
- return "MacClassic";
- case 18:
- return "MacIIsi";
- case 19:
- return "MacLC";
- case 20:
- return "Quadra900";
- case 21:
- return "Powerbook170";
- case 22:
- return "Quadra700";
- case 23:
- return "ClassicII";
- case 24:
- return "PowerBook100";
- case 25:
- return "PowerBook140";
-
- case 26:
- return "Quadra950";
- case 27:
- return "MacLCIII";
- case 29:
- return "PowerBookDuo210";
- case 30:
- return "MacCentris650";
- case 32:
- return "PowerBookDuo230";
- case 33:
- return "PowerBook180";
- case 34:
- return "PowerBook160";
- case 35:
- return "MacQuadra800";
- case 36:
- return "MacQuadra650";
- case 37:
- return "MacLCII";
- case 38:
- return "PowerBookDuo250";
- case 39:
- return "AWS9150_80";
- case 40:
- return "PowerMac8100_110";
- case 41:
- return "PowerMac5200";
- case 42:
- return "PowerMac6200";
- case 44:
- return "MacIIvi";
- case 45:
- return "MacIIvm";
- case 47:
- return "PowerMac7100_80";
- case 48:
- return "MacIIvx";
- case 49:
- return "MacColorClassic";
- case 50:
- return "PowerBook165c";
- case 52:
- return "MacCentris610";
- case 53:
- return "MacQuadra610";
- case 54:
- return "PowerBook145";
- case 55:
- return "PowerMac8100_100";
- case 56:
- return "MacLC520";
- case 57:
- return "AWS9150_120";
- case 60:
- return "MacCentris660AV";
- case 62:
- return "Performa46x";
- case 65:
- return "PowerMac8100_80";
- case 67:
- return "PowerMac9500";
- case 68:
- return "PowerMac7500";
- case 69:
- return "PowerMac8500";
- case 71:
- return "PowerBook180c";
- case 72:
- return "PowerBook5x0";
- case 75:
- return "PowerMac6100_60";
- case 77:
- return "PowerBookDuo270c";
- case 78:
- return "MacQuadra840AV";
- case 80:
- return "Performa550";
- case 84:
- return "PowerBook165";
- case 85:
- return "PowerBook190";
- case 88:
- return "MacTV";
- case 89:
- return "MacLC475";
- case 92:
- return "MacLC575";
- case 94:
- return "MacQuadra605";
- case 98:
- return "Quadra630";
- case 100:
- return "PowerMac6100_66";
- case 102:
- return "PowerBookDuo280";
- case 103:
- return "PowerBookDuo280c";
- case 108:
- return "PowerMac7200";
- case 112:
- return "PowerMac7100_66";
- case 115:
- return "PowerBook150";
- case 124:
- return "PowerBookDuo2300";
- case 126:
- return "PowerBook500PPCUpgrade";
- case 128:
- return "PowerBook5300";
-
- default:
- return "unknMachineType";
- end;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltMMUType()
- * Will return the memory management unit type found operating on the target.
- ************************************************************************************)
- task GetGestaltMMUType()
- begin
- gesAns := Gestalt('mmu ');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- mmuAns := GestaltGetValue(gesAns);
-
- if mmuAns = 0
- return "NoMMU";
-
- if mmuAns = 1
- return "AMU";
-
- if mmuAns = 2
- return "68851";
-
- if mmuAns = 3
- return "68030MMU";
-
- if mmuAns = 4
- return "68040MMU";
-
- return "unknMMUType";
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltPhysicalRAMSize()
- * Will return the amount of physical RAM located in a machine. This value is
- * an integer in megabytes.
- ************************************************************************************)
- task GetGestaltPhysicalRAMSize()
- begin
- gesAns := Gestalt('ram ');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- theHiWord := GestaltGetHiWord(gesAns);
- # Gestalt apparently has a problem reporting the full 8MB of physical memory
- # on machines with no virtual memory enabled. This will compensate.
- return (theHiWord + 1) / 16;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltProcessorType()
- * Will return the type of microprocessor running in the target machine.
- ************************************************************************************)
- task GetGestaltProcessorType()
- begin
- gesAns := Gestalt('proc');
- gesErr := GestaltGetError(gesAns);
- if (not gesErr)
- begin
- procAns := GestaltGetValue(gesAns);
-
- switch( procAns )
- begin
- case 1:
- return "68000";
- case 2:
- return "68010";
- case 3:
- return "68020";
- case 4:
- return "68030";
- case 5:
- return "68040";
- default:
- return "unknProc";
- end;
- end;
- else
- return GestaltGetLongError(gesAns);
- end;
-
- (************************************************************************************
- * Task GetGestaltVMAttr()
- * Will return the state of virtual memory on the target machine.
- ************************************************************************************)
- task GetGestaltVMAttr()
- begin
- gesAns := Gestalt('vm ');
- getErr := GestaltGetError(gesErr);
- if (not gesErr)
- begin
- vmAns := GestaltGetValue(gesAns);
- if vmAns & (1 << 0)
- return "VMPresent";
- if not (vmAns & (1 << 0))
- return "unknVMAttr";
- end;
- else
- return GestaltGetLongError(gesAns);
- end;